package com.example.front.controller;

import com.example.front.dao.RecordDao;
import com.example.front.dao.OperationRecordMapper;
import com.example.front.dao.OperationRecordPO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * Index1Controller
 *
 * @author liming2
 * @date 2023/10/27 17:58
 */
@Slf4j
@RestController
public class JsonController {

    private static final Logger logger = LoggerFactory.getLogger(JsonController.class);

    @Autowired
    private OperationRecordMapper operationRecordMapper;

    @Autowired
    private RecordDao recordDao;

    @GetMapping("/insert")
    public void game(String ip, String host, HttpServletRequest request) {
        OperationRecordPO recordPO = OperationRecordPO.builder()
                .operator(StringUtils.isNoneBlank(ip) ? ip : "xx")
                .operateTime(new Date())
                .type(2)
                .content(StringUtils.isNoneBlank(host) ? host : "yy")
                .extra("xx")
                .build();
        logger.info("result:{}, ip:{}, host:{}", operationRecordMapper.insert(recordPO), ip, host);
    }

    @GetMapping("/query")
    public List<OperationRecordPO> list() {
        log.info("query:{}", 111);
        return operationRecordMapper.query();
    }
}
